Barcode Xpress for Node.js v13.5 - Updated
Create Your First Project
Getting Started > Create Your First Project

This step-by-step tutorial will guide you to build a complete application that analyzes a Code 39 barcode from an image and output the value, type, location and confidence to the terminal. NOTE: You may want to try our sample application first before creating your first project.

For this tutorial, you can use any text editor (vim, gedit, emacs, etc.).

Steps:

  1. Create a new file titled BXDemo.js
  2. Import the Barcode module:
    JavaScript
    Copy Code
    const bx = require("barcode-js");
    
  3. Create the parameters to use for recognition - namely, the input image and the barcode type to recognize. Change the file name in this example to an image on your local system.:
    JavaScript
    Copy Code
    const filePath = "filePath/fileName.bmp";
    const params = {
        type: bx.BarcodeType.ALL
    };
    
    Specifying only the barcode type or types that you are interested in will speed up the analysis. For example, you can use "code39", ["code39", "code128"], or "all". If you omit the barcode type completely, "all" is assumed.
  4. Perform analyze on your barcode image:
    JavaScript
    Copy Code
    const analyzeBarcodes = async (filePath, params) => {
        try {
            const results = await bx.analyze(filePath, params);
            console.log(JSON.stringify(results, ["type", "value", "confidence"], 2));
        }
        catch(err) {
            console.error(`There was an error processing this image\n${err}`);
        }
    }
    
    analyzeBarcodes(filePath, params);
    
  5. That’s it! Now go to the console and run your application to see the result output data:
    Copy Code
    $ node BXDemo